package com.tuyou.test2;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Uri uri = Uri.parse("content://com.tuyou.mycontentprovider/user");

        ContentValues values = new ContentValues();
        values.put("_id", 3);
        values.put("name", "zhangsan");

        ContentResolver contentResolver = getContentResolver();
        contentResolver.insert(uri, values);

        Cursor cursor = contentResolver.query(uri, new String[]{"_id", "name"}, null, null, null);
        while(cursor.moveToNext()){
            System.out.println("query user:" + cursor.getInt(0) + " " + cursor.getString(1));
        }
        cursor.close();

        uri = Uri.parse("content://com.tuyou.mycontentprovider/job");
        values = new ContentValues();
        values.put("_id", 3);
        values.put("job", "NBA");

        contentResolver.insert(uri, values);

        cursor = contentResolver.query(uri, new String[]{"_id", "job"}, null, null, null);
        while(cursor.moveToNext()){
            System.out.println("query job:" + cursor.getInt(0) + " " + cursor.getString(1));
        }
        cursor.close();
    }
}
